<?php
include_once 'MY/extra_sql.php';
function merger($arr,$data) {
    $array=array('0'=>'0');
    $j=count($data);
    for($i=0;$i<$j;$i++) {
        if(!in_array($data[$i],$arr)) {
            $array[].=$data[$i];
        }
    }
    return $array;
}
class ClassController extends Zend_Controller_Action{
	function init(){
		if($_SESSION['user']==""){
			echo "<script>window.location='../user/login';</script>"; exit;
		}
		$this->registry = Zend_Registry::getInstance();
		$this->view = $this->registry['view'];
		$this->view->baseUrl = $this->_request->getBaseUrl();
		$this->view->template = "class";
		$this->view->conf = new Zend_Config(require './application/configs/config.php');

		$group_id = $_SESSION['user']['group_id'];
		$group = new Group();
		$group = $group->getgroupByid($group_id);
		$groups = explode(',',$group[0]['models']);
		if(!in_array('class',$groups)){
			echo "<script>alert('No Permission To Enter!');history.go('-1');</script>";exit();
		}
	}

	public function indexAction(){
		$class = new Classes();
		$classes = $class->getAllClasses('','','','','','');
		$this->view->total = count($classes);
		$this->view->top = $class->getTopClasses();
		
		//班级统计
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrClassType[] = array(0,0,0,0,0,0);
		}
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrClass = array();

		foreach($arrTime as $key=>$row){
			$arrClass = $class->getClassByTime($row[0] ,$row[1]);
			foreach($arrClass as $k=>$v){
				$arrClassType[$key][$arrClass[$k]['category']]++;
			}

			$arrClassType[$key]['year'] = $arrYear[$key];
		}
		
		$cc = array();
	    foreach ($arrClassType as $k=>$v){
	    	$j=0;
	    	for($i=0;$i<count($v);$i++){
	    	  $cc[$i]+=$v[$i];	
	    	}	    	
	    }
	    $cc['year'] = '小结';
        $arrClassType[] = $cc;
        
//		echo '<pre>';
//		print_r($arrClassType);exit;
		//排列统计
		$studentclass = new StudentClass();
		$arrStudentClass = $studentclass->getAll();
		if (!empty($arrStudentClass)) {
			foreach($arrStudentClass as $key=>$row){
				$arrStudentNum[$row['class_id']]++;
				if ($row['passed'] == 1 || $row['passed'] == 3) {
					$arrStudentPass[$row['class_id']]++;
				}
				if ($row['passed'] == 2 || $row['passed'] == 4 || $row['passed'] == 5 || $row['passed'] == 0) {
					$arrStudentNoPass[$row['class_id']]++;
				}
				$arrPassRate[$row['class_id']] = $arrStudentPass[$row['class_id']]/$arrStudentNum[$row['class_id']];
			}
			
			if (!empty($arrStudentNum)) {
				arsort($arrStudentNum);
				$arrStudentNum = array_slice($arrStudentNum,0,10,true);
				foreach($arrStudentNum as $key=>$row){
					$arrClass1 = $class->getclassByclass_id($key);
					$arrClass1[0]['num'] = $arrStudentNum[$key];
					$arrStat1[] = $arrClass1[0];
				}
				$this->view->arrStat1 = $arrStat1;
			}else{
				$this->view->arrStat1 = array();
			}
			
			if (!empty($arrStudentNoPass)) {
				arsort($arrStudentNoPass);
				$arrStudentNoPass = array_slice($arrStudentNoPass,0,10,true);
				foreach($arrStudentNoPass as $key=>$row){
					$arrClass2 = $class->getclassByclass_id($key);
					$arrClass2[0]['pass'] = $arrStudentNoPass[$key];
					$arrStat2[] = $arrClass2[0];
				}
				$this->view->arrStat2 = $arrStat2;
			}else{
				$this->view->arrStat2 = array();
			}
			
			if (!empty($arrPassRate)) {
				arsort($arrPassRate);
				$arrPassRate = array_slice($arrPassRate,0,10,true);
				foreach($arrPassRate as $key=>$row){
					$arrClass3 = $class->getclassByclass_id($key);
					$arrClass3[0]['pass_rate'] = sprintf("%.2f".'％',$arrPassRate[$key]*100);
					$arrStat3[] = $arrClass3[0];
				}
				$this->view->arrStat3 = $arrStat3;
			}else{
				$this->view->arrStat3 = array();
			}
			
			$arrClassOrderIncome = $class->getClassOrderIncome();
			$this->view->arrStat4 = $arrClassOrderIncome;
			$this->view->arrClassType = $arrClassType;
		}
		echo $this->view->render('class/index.html');
	}

	//添加班级阶段
	public function Action(){
		$filter = new Zend_Filter_StripTags();
		$classmission = new ClassMission();
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$class_id = $filter->filter(($this->_request->getPost('class_id')));
			$mission_name = $filter->filter(($this->_request->getPost('mission_name')));
			$start_time = $filter->filter(($this->_request->getPost('start_time')));
			$end_time = $filter->filter(($this->_request->getPost('end_time')));
			$remark = $filter->filter(($this->_request->getPost('remark')));
			$start_time = strtotime($start_time);
			$end_time = strtotime($end_time);

			$data = array(
				'class_id'=>$class_id,
				'mission_name'=>$mission_name,
				'start_time'=>$start_time,
				'end_time'=>$end_time,
				'remark'=>$remark
			);
			$id = $classmission->insert($data);
			if($id){
			   echo "<script>window.location='#'</script>";
			}else{
			   echo "<script>alert('Failure!');window.location='#'</script>";
			}
		}
	}

	//添加班级方法
	public function addAction(){
		$filter=new Zend_Filter_StripTags();
		$classes = new Classes();
		$class = new ClassTeacher();
		$operation = new Operation();
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$name=$filter->filter(($this->_request->getPost('name')));
			$location=$filter->filter(($this->_request->getPost('location')));
			$summary=$this->_request->getPost('summary');
			$start_time=$filter->filter(($this->_request->getPost('start_time')));
			$end_time=$filter->filter(($this->_request->getPost('end_time')));
			$is_complete=$filter->filter(($this->_request->getPost('is_complete')));
			$linkman=$filter->filter(($this->_request->getPost('linkman')));
			$category=$filter->filter(($this->_request->getPost('category')));
			$income=$filter->filter(($this->_request->getPost('income')));
			$rate=$filter->filter(($this->_request->getPost('rate')));
            $user_id=$_SESSION['user']['user_id'];
			$start_time = strtotime($start_time);
			$end_time = strtotime($end_time);
			$data = array(
				'name'=>$name,
				'location'=>$location,
				'summary'=>$summary,
				'start_time'=>$start_time,
				'end_time'=>$end_time,
				'is_complete'=>$is_complete,
				'linkman'=>$linkman,
				'category'=>$category,
				'income'=>$income,
			    'user_id'=>$user_id,
			    'rate'=>$rate
			 );

			$class_id = $classes->insert($data);

			if($class_id){
				$time = time();
				$data = array(
					'op_name'=>'add',
					'model_name'=>'class',
					'user_id'=>$_SESSION['user']['user_id'],
					'user_name'=>$_SESSION['user']['user_name'],
					'name'=>'增加班级',
					'create_time'=>$time
				);
				$query = $operation->insert($data);                
				echo "<script>window.location='detail?class_id=".$class_id."'</script>";
			}else{
				 
			}
		}
		echo $this->view->render('class/add.html');
	}

	//修改班级方法
	public function editAction(){
		$filter=new Zend_Filter_StripTags();
		$classes = new Classes();
		$teacher = new Teacher();
        $operation = new Operation();
        $classteacher = new ClassTeacher();
		$class_id=$filter->filter(($this->_request->getParam('class_id')));

		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$name=$filter->filter(($this->_request->getPost('name')));
			$location=$filter->filter(($this->_request->getPost('location')));
			$summary=$this->_request->getPost('summary');
			$start_time=$filter->filter(($this->_request->getPost('start_time')));
			$end_time=$filter->filter(($this->_request->getPost('end_time')));
			$is_complete=$filter->filter(($this->_request->getPost('is_complete')));
			$linkman=$filter->filter(($this->_request->getPost('linkman')));
			$category=$filter->filter(($this->_request->getPost('category')));
			$income=$filter->filter(($this->_request->getPost('income')));
			$rate=$filter->filter(($this->_request->getPost('rate')));
			$start_time = strtotime($start_time);
			$end_time = strtotime($end_time);
			$data = array(
				'name'=>$name,
				'location'=>$location,
				'summary'=>$summary,
				'start_time'=>$start_time,
				'end_time'=>$end_time,
				'is_complete'=>$is_complete,
				'linkman'=>$linkman,
				'category'=>$category,
				'income'=>$income,
			    'rate'=>$rate
			 );

			$query = $classes->updateclassByclass_id($data, $class_id);
			if($query){
				$time = time();
				$data = array(
					'op_name'=>'edit',
					'model_name'=>'class',
					'user_id'=>$_SESSION['user']['user_id'],
					'user_name'=>$_SESSION['user']['user_name'],
					'name'=>'修改班级',
					'create_time'=>$time
				);
				$query = $operation->insert($data);
				echo "<script>window.location='detail?class_id=".$class_id."'</script>";
			}
		}else{
			$this->view->class=$classes->getclassByclass_id($class_id);
		}
    	echo $this->view->render('class/edit.html');
	}

	//班级列表页
	public function listAction(){
		$filter=new Zend_Filter_StripTags();
		$classes = new Classes();
                $operation  = new Operation();
		$db = new mysql(constant('dbhost'),constant('dbuser'),constant('dbpass'),constant('dbname'),"UTF8");
		$page=$filter->filter(($this->_request->getParam('page')));
		$search_name=$filter->filter(($this->_request->getParam('search_name')));
		$teacher_name=$filter->filter(($this->_request->getParam('teacher_name')));
		$search_start_time=$filter->filter(($this->_request->getParam('search_start_time')));
		$search_location=$filter->filter(($this->_request->getParam('search_location')));

		$search_start_time = strtotime($search_start_time);
		if($page==""){
			$page="1";
		}
		$teacher_id="";
		if($teacher_name!=""){
			$teacher = new Teacher();
			$teachers = $teacher->getteacherLikename($teacher_name);
			$teacher_id = $teachers[0]['teacher_id'];
		}
		//$count = $db->select_classes('','','',$search_name,$search_start_time,$search_location);
        $count = $classes->getAllClasses('','','',$search_name,$search_start_time,$search_location);

		//总条数
		$total = count($count);
		//总页数
		$perpage = "10";
		$pages = ceil($total/$perpage);
		$start = ($page-1)*$perpage;
		$end = $perpage;
		//$this->view->classes = $db->select_classes($start,$end,$teacher_id,$search_name,$search_start_time,$search_location);
        $this->view->classes = $classes->getAllClasses($page, $perpage, $teacher_id, $search_name, $search_start_time, $search_location);
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;


		$time = time();
		$data = array(
			'op_name'=>'list',
			'model_name'=>'class',
			'user_id'=>$_SESSION['user']['user_id'],
			'user_name'=>$_SESSION['user']['user_name'],
			'name'=>'取得所有班级',
			'create_time'=>$time
		);
		$query = $operation->insert($data);
		echo $this->view->render('class/list.html');
	}

	//班级详情页
	public function detailAction(){
		$filter=new Zend_Filter_StripTags();
		$classes = new Classes();
		$teacher = new Teacher();
		$student = new Student();
		$course = new Course();
		$project = new Project();
		$company = new Company();
        $operation = new Operation();
        $classteacher = new ClassTeacher();
		$db = new mysql(constant('dbhost'),constant('dbuser'),constant('dbpass'),constant('dbname'),"UTF8");
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
		$page=$filter->filter(($this->_request->getParam('page')));
		$pro_page=$filter->filter(($this->_request->getParam('pro_page')));
		$this->view->projects = $project->getprojectByclass_id($class_id);
		$this->view->class = $classes->getclassByclass_id($class_id);
	    if ($pro_page=="") {
			$pro_page="1";
		}
		
		//班级相关学生
		$studentclass = new StudentClass();
		$arrStudentClasss = $studentclass->getstudent_classByclass_id($class_id,9999,'');
		$pro_total = count($arrStudentClasss);
		$intStudentAllNum = count($arrStudentClasss);
		$passnum=0;
		$notpassnum=0;
		foreach($arrStudentClasss as $key=>$row){
		if($row['passed']==0){
				$notpassnum++;
			}else if($row['passed']==1){
				$passnum++;
			}			
		}
		//总页数
		$perpage = "10";
		$pro_pages = ceil($pro_total/$perpage);
		$pro_start = ($pro_page-1)*$perpage;
		$pro_end = $perpage;
		$this->view->pro_page = $pro_page;
		$this->view->pro_pages = $pro_pages;
		$this->view->pro_total = $pro_total;
		$arrStudentClass = $studentclass->getstudent_classByclass_id($class_id,$pro_page,$pro_end);
		
		
		foreach($arrStudentClass as $key=>$row){
			$arrStudent = $student->getStudentBystudent_id($row['student_id']);
			$arrCompany = $company->getCompanyBycompany_id($arrStudent[0]['company_id']);
			$arrStudentClass[$key]['student_name'] = $arrStudent[0]['name'];
			$arrStudentClass[$key]['duties'] = $arrStudent[0]['duties'];
			$arrStudentClass[$key]['student_id'] = $row['student_id'];
			$arrStudentClass[$key]['company_id'] = $arrCompany[0]['company_id'];
			$arrStudentClass[$key]['company_name'] = $arrCompany[0]['name'];
			$arrStudentName[$row['category']][] = $arrStudentClass[$key]['student_name'];
			$arrStudentExam[$row['exam']][] = $arrStudentClass[$key]['student_name'];
			
		}
		$strStudent0 = !empty($arrStudentName[1])?implode('，',$arrStudentName[1]):'未填写';
		
		for($i=0;$i<=6;$i++){
			$str = "intExamNum".$i;
			$$str = count($arrStudentExam[$i]);
		}
		$this->view->intAllNum = $intStudentAllNum;
		$this->view->intPassNum = $passnum;
		if ($intStudentAllNum > 0){
			$this->view->passRate = sprintf("%.2f".'％',($passnum)/$intStudentAllNum*100);
		}else{
			$this->view->passRate = '0%';
		}
		$this->view->intPassNum1 = $intExamNum2;
		$this->view->intNoPassNum = $notpassnum;
		
		$this->view->strTeacher0 = $strTeacher0;
		$this->view->arrStudentClass = $arrStudentClass;
		
		
		//教师相关信息
		$classteacher = new ClassTeacher();
		$arrClassTeacher = $classteacher->getclass_teacherByclassid($class_id);
		if (!empty($arrClassTeacher)) {
			foreach($arrClassTeacher as $key=>$row){
				$arrTeacher = $teacher->getteacherByteacher_id($row['teacher_id']);
				$arrClassTeacher[$key]['teacher_name'] = $arrTeacher[0]['name'];
				$arrTeacherName[$row['category']][] = $arrClassTeacher[$key]['teacher_name'];
			}
			$strTeacher0 = !empty($arrTeacherName[0])?implode('，',$arrTeacherName[0]):'未填写';
			$strTeacher1 = !empty($arrTeacherName[1])?implode('，',$arrTeacherName[1]):'未填写';
			
			$this->view->strTeacher0 = $strTeacher0;
			$this->view->strTeacher1 = $strTeacher1;
		}
		
  		//comment的页数
		if($page==""){
			$page="1";
		}
		//查询所有的comment和发表comment的用户名
		$count = $db->select_comment('','',$class_id,'3');
		//总条数
		$total = count($count);
		//总页数
		$perpage = "2";
		$pages = ceil($total/$perpage);
		$start = ($page-1)*$perpage;
		$end = $perpage;
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;

		$this->view->comments = $db->select_comment($start,$end,$class_id,'3');


		$time = time();
		$data = array(
			'op_name'=>'detail',
			'model_name'=>'class',
			'user_id'=>$_SESSION['user']['user_id'],
			'user_name'=>$_SESSION['user']['user_name'],
			'name'=>'查看班级详情',
			'create_time'=>$time
		);
		$query = $operation->insert($data);

		echo $this->view->render('class/detail.html');
	}
	
	//删除班级方法
	public function deleteAction(){
		$filter=new Zend_Filter_StripTags();
		$classes = new Classes();
        $operation = new Operation();
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
		$query = $classes->delclassByclass_id($class_id);
		if($query){
			$time = time();
			$data = array(
				'op_name'=>'delete',
				'model_name'=>'class',
				'user_id'=>$_SESSION['user']['user_id'],
				'user_name'=>$_SESSION['user']['user_name'],
				'name'=>'删除班级',
				'create_time'=>$time
			);
			$query = $operation->insert($data);
			echo "<script>window.location='list'</script>";
		}else{
			
		}
	}

	public function hoverAction(){
		$filter=new Zend_Filter_StripTags();
		$classes = new Classes();
        $search_name=$filter->filter(($this->_request->getParam('search_name')));
		$this->view->classes = $classes->getAllClasses('','','',$search_name,'','');
		echo $this->view->render('class/hover.html');
	}
	
	public function teacherAction(){
		$filter=new Zend_Filter_StripTags();
        $db = new mysql(constant('dbhost'),constant('dbuser'),constant('dbpass'),constant('dbname'),"UTF8");
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
        $search=$filter->filter(($this->_request->getParam('search')));
		$class = new Classes();
		$teacher = new Teacher();
		$classteacher = new ClassTeacher();
		$this->view->class = $class->getclassByclass_id($class_id);
		$this->view->teachers = $teacher->getAllTeachers('','', $search);

		$currentteacher = $classteacher->getclass_teacherByclassid($class_id);
		$array = array('0'=>'0');
		for($i=0;$i<count($currentteacher);$i++){
			$array[].=$currentteacher[$i]['teacher_id'];
		}
		$headteacher = $classteacher->getclass_teacherBytype($class_id,'1');
        $this->view->teacher_count = count($headteacher);
		$this->view->teacher =  $db->select_classteacher($class_id);
		$this->view->classteachers = $currentteacher;
		echo $this->view->render('class/teacher.html');
	}

	public function teacheraddAction(){
		$filter=new Zend_Filter_StripTags();
		$classteacher = new ClassTeacher();
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$class_id=$filter->filter(($this->_request->getPost('class_id')));
			$teacher_id = $_POST['teacher_id'];
			$count = count($teacher_id);
			if($count!=0){
				for($i=1;$i<=$count;$i++){
					$data=array(
					  'class_id'=>$class_id,
					  'teacher_id'=>$teacher_id[$i-1],
					  'category'=>'0',
					  'remark'=>''
					);
					$classteacher->insert($data);
					unset($data);
				}
				echo "<script>window.location='teacher?class_id=".$class_id."'</script>";
			}
		}
	}

	public function teacherdelAction(){
		$filter=new Zend_Filter_StripTags();
		$classteacher = new ClassTeacher();
		$id=$filter->filter(($this->_request->getParam('id')));
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
		$query = $classteacher->delclass_teacherByid($id);
		if($query){
			echo "<script>window.location='teacher?class_id=".$class_id."'</script>";
		}
	}
        
	public function teachertypeAction(){
		$filter=new Zend_Filter_StripTags();
		$classteacher = new ClassTeacher();
		$id=$filter->filter(($this->_request->getParam('id')));
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
		$type=$filter->filter(($this->_request->getParam('type')));
		$classteacheres = $classteacher->getclass_teacherByclassid($class_id);
		$arr=array('0'=>'0');
		for($i=0;$i<count($classteacheres);$i++){
			$arr[].=$classteacheres[$i]['id'];
		}
		//print_r($arr);exit;
		$data = array('0'=>$id);
		$leftteacher = merger($data,$arr);
		$data = array(
			'category'=>$type
		);
	    
		$query = $classteacher->updateclass_teacherByid($data, $id);
		
		if($query){
			$array = array(
				'category'=>'0'
			);
			for($i=0;$i<count($leftteacher);$i++){
				$query = $classteacher->updateinarray($array, $leftteacher[$i]['id']);
			}
			
			if($query){
				echo "<script>window.location='teacher?class_id=".$class_id."'</script>";
			}
		}
	}

	public function studentaddAction(){
		$filter=new Zend_Filter_StripTags();
		$studentclass = new StudentClass();
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$class_id=$filter->filter(($this->_request->getPost('class_id')));
			$student_id=$_POST['student_id'];
			$count = count($student_id);
			if($count!=0){
				for($i=1;$i<=$count;$i++){
					$data=array(
					  'class_id'=>$class_id,
					  'student_id'=>$student_id[$i-1]
					);
					$studentclass->insert($data);
					unset($data);
				}
				echo "<script>window.location='student?class_id=".$class_id."'</script>";
			}else{
				echo "<script>window.location='student?class_id=".$class_id."'</script>";
			}
		}
	}

	public function studentAction(){
		$filter=new Zend_Filter_StripTags();
        $db = new mysql(constant('dbhost'),constant('dbuser'),constant('dbpass'),constant('dbname'),"UTF8");
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
        $search=$filter->filter(($this->_request->getParam('search')));
		$class = new Classes();
		$studentclass = new StudentClass();
		$student = new Student();
		$this->view->class = $class->getclassByclass_id($class_id);
		$current = $studentclass->getstudent_classByclass_id($class_id,9999,'');
		$this->view->student = $db->select_classstudent($class_id);
        if (!empty($search)) {
			$this->view->students = $student->getAllStudents('','',$search);
			$arr = array('0'=>'0');
			for($i=0;$i<count($current);$i++){
				$arr[].=$current[$i]['student_id'];
			}
        } else {
        	$this->view->students = $student->getAllStudents('','','');
        }
        $this->view->studentAll = count($student->getAllStudents('','',''));
        $this->view->studentSelect = count($current);

		echo $this->view->render('class/student.html');
	}

    public function studentdelAction(){
		$filter=new Zend_Filter_StripTags();
		$studentclass = new StudentClass();
		$id=$filter->filter(($this->_request->getParam('id')));
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
		$query = $studentclass->delstudent_classByid($id);
		if($query){
		   echo "<script>window.location='student?class_id=".$class_id."'</script>";
		}
	}

	public function missionAction(){
		$filter=new Zend_Filter_StripTags();
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
        $num=$filter->filter(($this->_request->getParam('num')));
		$class = new Classes();
        $classmission = new ClassMission();
        $this->view->class = $class->getclassByclass_id($class_id);
		$this->view->missions = $classmission->getclass_missionByclass_id($class_id);
		echo $this->view->render('class/mission.html');
	}

	public function addmissionAction(){
		$filter=new Zend_Filter_StripTags();
		$classmission = new ClassMission();
		
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$class_id=$filter->filter(($this->_request->getPost('class_id')));
			$name=$_POST['name'];
			$start_time=$_POST['start_time'];
			$end_time=$_POST['end_time'];
			$remark=$_POST['remark'];
			$count = count($name);
			if($count!=0){
				for($i=1;$i<=$count;$i++){
					$data=array(
					  'class_id'=>$class_id,
					  'mission_name'=>$name[$i-1],
					  'start_time'=>$start_time[$i-1],
					  'end_time'=>$end_time[$i-1],
					  'remark'=>$remark[$i-1]
					);
					$classmission->insert($data);
					unset($data);
				}
				echo "<script>window.location='mission?class_id=".$class_id."'</script>";
			}
		}
	}

	public function editmissionAction(){
		$filter=new Zend_Filter_StripTags();
		$classmission = new ClassMission();
		
		if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
			$class_id=$filter->filter(($this->_request->getPost('class_id')));
			$mission_id=$filter->filter(($this->_request->getPost('mission_id')));
			$name=$filter->filter(($this->_request->getPost('name')));
			$start_time=$filter->filter(($this->_request->getPost('start_time')));
			$end_time=$filter->filter(($this->_request->getPost('end_time')));
			$remark=$filter->filter(($this->_request->getPost('remark')));
			$data=array(
				'class_id'=>$class_id,
				'mission_name'=>$name,
				'start_time'=>$start_time,
				'end_time'=>$end_time,
				'remark'=>$remark
			);
			$query = $classmission->updateclass_missionByid($data, $mission_id);
			if($query){
				echo "<script>window.location='mission?class_id=".$class_id."'</script>";
			}
		}
	}

    public function delmissionAction(){
		$filter=new Zend_Filter_StripTags();
		$classmission = new ClassMission();
		$mission_id=$filter->filter(($this->_request->getPost('mission_id')));
		$class_id=$filter->filter(($this->_request->getParam('class_id')));
		$query = $classmission->delclass_missionByid($mission_id);
		if($query){
		   echo "<script>window.location='mission?class_id=".$class_id."'</script>";
		}
	}
	
	public function updateclassstudentAction(){
		$filter=new Zend_Filter_StripTags();
		$studentclass = new StudentClass();
		$student_id=$filter->filter(($this->_request->getPost('student_id')));
		$class_id=$filter->filter(($this->_request->getPost('class_id')));
		$note=$filter->filter(($this->_request->getPost('note')));
		$payment=$filter->filter(($this->_request->getPost('payment')));
		$exam=$filter->filter(($this->_request->getPost('exam')));
		$data=array(
			'note'=>$note,
			'payment'=>$payment,
			'exam'=>$exam,
		);
		$query = $studentclass->updateStudentClass($data,$student_id,$class_id);
		if($query){
			echo "<script>window.location='detail?class_id=".$class_id."&student_id=".$student_id."'</script>";
		}
	}
	
	public function typestatAction(){
		$filter=new Zend_Filter_StripTags();
		$year=$filter->filter(($this->_request->getParam('year')));
		$category=$filter->filter(($this->_request->getParam('category')));
		$page=$filter->filter(($this->_request->getParam('page')));
		$page = !empty($page)?$page:1;
		$class = new Classes();
		$time1 = strtotime($year.'-01-01');
		$time2 = strtotime(($year+1).'-01-01');
		$arrClass = $class->getClassByTimeType($time1,$time2,$category);
		$total = count($arrClass);
		$perpage = 10;
		$arrClass = array_slice($arrClass,($page-1)*$perpage,$perpage);
		foreach($arrClass as $key=>$row){
			
		}
		$this->view->arrClass = $arrClass;
		
		$pages = ceil($total/$perpage);
		$this->view->page = $page;
		$this->view->pages = $pages;
		$this->view->total = $total;
		
		echo $this->view->render('class/typestat.html');
	}
	
	public function bars1Action(){
		//班级统计
		$class = new Classes();
		$arrDate = getdate();
		$year = $arrDate['year']+1;
		$time = strtotime($year.'-01-01');
		$arrTime = array();
		$project_type = $this->view->conf ->projectType;
		for ($i=0;$i<8;$i++) {
			$arrTime[] = array(strtotime(($year-1).'-01-01'), strtotime(($year).'-01-01'));
			$year--;
			$arrYear[] = $year;
			$arrClassType[] = array(0,0,0,0,0,0);
		}
		foreach($arrYear as $row){
			$arrYearShow[] = strval($row);
		}
		$arrClass = array();
		foreach($arrTime as $key=>$row){
			$arrClass = $class->getClassByTime($row[0] ,$row[1]);
			foreach($arrClass as $k=>$v){
				$arrClassType[$key][$arrClass[$k]['category']]++;
			}
			//$arrClassType[$key]['year'] = $arrYear[$key];
		}
		
		$count = count($arrClassType);
		for($i=0;$i<$count;$i++){
			foreach($arrClassType[$i] as $key=>$row){
				$arrTypeNum[$key][] = $row;
			}
		}
		require_once('./public/chart/php-ofc-library/open-flash-chart.php');
		
		$title = new title( date("班级数量分布") );
		
		foreach ($project_type as $v=>$l){
			$arr[] = $arrTypeNum[$v ];
			$s[] = max($arrTypeNum[$v ]);
		}
		 
		$intMax = max($s);
		$y_num = ($intMax>=10)?ceil($intMax/10)*10:10;
		$ss = array();
				$y = new y_axis(); 
		$y->set_range( 0, $y_num, $y_num/10 );
		
		$x = new x_axis();
		$x->set_labels_from_array( $arrYearShow );
		
		$chart = new open_flash_chart();
		$chart->set_title( $title );
		
		foreach($project_type as $k=>$val){        
					$bar =  new bar_glass();
					$bar->set_values( $arr[$k] );
					$bar->set_colour(rand_color());
					$bar->set_on_show(new bar_on_show('pop-up',0.5,0.2));
					$bar->set_tooltip( $val.'：#val#' );			
					$chart->add_element( $bar );
					$ss[] = $bar;
		}
		$chart->set_y_axis( $y );
		$chart->set_x_axis( $x );
		
		echo $chart->toPrettyString();
	}
}
?>
